/************************************轮播图************************************/

var $1_time = 800;	//控制轮播图时间

var $1_content = document.getElementById("content");
var $1_lis = $1_content.getElementsByTagName("li");    //拿到所有的li标签
var $1_imgs = $1_content.getElementsByTagName("img");  // 拿到所有的图片
var $1_$length = $1_imgs.length - 1;
var $1_index = 0;
var $1_res;    //定时器的返回值 用时控制停止播放

//当页面加载结束后，自动调用定时器运行轮播图
$1_interval();

//当鼠标移动$1_content中时 设置轮播图停止播放
$1_content.onmouseover = function () {
    clearInterval($1_res);
}
$1_content.onmouseout = function () {
    $1_interval();
}

//监听左边/右边
var $1_leftAndRight = $1_content.getElementsByTagName("span");
for (let g = 0; g < $1_leftAndRight.length; g++) {
    $1_leftAndRight[g].onclick = function () {
        if (this.innerText == "<") {
            if ($1_index == 0) {
                $1_index = $1_$length + 1;
            }
            $1_index--;
        } else if (this.innerText == ">") {
            if ($1_index == $1_$length) {
                $1_index = -1;
            }
            $1_index++;
        }
        $1_setIndex();
    }
}

//监听li标签
for (let j = 0; j < $1_$length + 1; j++) {
    $1_lis[j].onmouseover = function () {
        $1_index = j;
        $1_setIndex();
    }
}

/*设置轮播图自动播放*/
function $1_interval() {
    $1_res = setInterval(function () {
        $1_imgs[$1_index].style.display = "none";
        $1_lis[$1_index].style.backgroundColor = "#fff";
        $1_index++;
        if ($1_index > $1_$length) {
            $1_index = 0;
        }
        $1_imgs[$1_index].style.display = "block";
        $1_lis[$1_index].style.backgroundColor = "red";
    }, $1_time);
};

/*切换图片时调用*/
function $1_setIndex() {
    //设置所有图片 隐藏
    for (var k = 0; k < $1_$length + 1; k++) {
        $1_imgs[k].style.display = "none";
        $1_lis[k].style.backgroundColor = "#fff";
    }
    //设置当前$1_index的图片和li显示并且指定样式
    $1_imgs[$1_index].style.display = "block";
    $1_lis[$1_index].style.backgroundColor = "red";
}
/******************************************************************************/
